/*
 * This file is part of the Refran Library
 * Copyright (C) 2009 César Enrique García
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/** @file
 * $Author: cquike $
 * $Date: 2010-10-21 16:14:44 +0000 (Thu, 21 Oct 2010) $
 * $Revision: 230 $
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef REFRAN_LOGGER_H
#define REFRAN_LOGGER_H

#include <memory>
#include <utility>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/Category.hh>

namespace Refran
{

    /**
     * This class implements the logging facility.
     * By default it logs to stdout, but it can be configured
     * with other log4cpp Category (in log4cpp jargon).
     * Classes that want to use this facility just should
     * derive from it and use the info_(), warning_() and error_()
     * protected methods.
     */
    class Logger
    {
        public:

        /**
         * Constructor with the name of the default logging facility.
         */
        Logger(const std::string& name = "refran");

        /**
         * Destructor
         */
        virtual ~Logger();

        /**
         * Set a new appender (for instance FileAppender)
         */
        void setAppender(log4cpp::Appender& appender);

        /**
         * Set a new logging facility
         */
        void setLogger(const std::string& newLoggerName);

        protected:

        /**
         * Output to the debug logging facility
         */
        template<typename... Args>
        void debug_(const std::string& message, Args... args);

        /**
         * Output to the debug logging facility
         */
        template<typename... Args>
        void debug_(char const* message, Args... args);

        /**
         * Output to the info logging facility
         */
        template<typename... Args>
        void info_(const std::string& message, Args... args);

        /**
         * Output to the info logging facility
         */
        template<typename... Args>
        void info_(char const* message, Args... args);

        /**
         * Output to the warning logging facility
         */
        template<typename... Args>
        void warning_(const std::string& message, Args... args);

        /**
         * Output to the warning logging facility
         */
        template<typename... Args>
        void warning_(char const* message, Args... args);

        /**
         * Output to the error logging facility
         */
        template<typename... Args>
        void error_(const std::string& message, Args... args);

        /**
         * Output to the error logging facility
         */
        template<typename... Args>
        void error_(char const* message, Args... args);

        private:

        /**
         * Initialize the looger
         */
        void initDefaultLogger_();

        /**
         * The used logger
         */
        log4cpp::Category* m_logger;

        /**
         * The default logger. This is cached for better performance.
         * So that each Logger does not have to create the default appender by itself.
         */
        static std::unique_ptr<log4cpp::OstreamAppender> defaultStdoutAppender;
    };


}// namespace Refran

#include "Logger_T.cpp"

#endif // REFRAN_LOGGER_H
